import request from "@/utils/request";
import { AxiosPromise } from "axios";
import { MaterialType, AddOrUpMaterial, DelMaterial, AddOrUpUnit, DelUnit, Material, Detail } from "./types";

/**
 * 获取物料分类列表
 * @param data
 */
export function getMaterialType(data: MaterialType): AxiosPromise<any> {
  return request({
    url: "/stasx/store/materialType/list/v1",
    method: "get",
    params: data,
  });
}

/**
 * 新增或修改物料分类
 * @param data
 */
export function addOrUpdateMaterialType(data: AddOrUpMaterial): AxiosPromise<any> {
  return request({
    url: "/stasx/store/materialType/addOrUpdate/v1",
    method: "post",
    data,
  });
}

/**
 * 删除物料分类
 * @param data
 */
export function delMaterialType(data: DelMaterial): AxiosPromise<any> {
  return request({
    url: "/stasx/store/materialType/delMaterialType/v1",
    method: "post",
    data,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
  });
}

/**
 * 获取物料单位列表
 * @param data
 */
export function getMaterialUnit(data: MaterialType): AxiosPromise<any> {
  return request({
    url: "/stasx/store/materialUnit/list/v1",
    method: "get",
    params: data,
  });
}

/**
 * 新增或修改物料单位
 * @param data
 */
export function addOrUpdateMaterialUnite(data: AddOrUpUnit): AxiosPromise<any> {
  return request({
    url: "/stasx/store/materialUnit/addOrUpdate/v1",
    method: "post",
    data,
  });
}

/**
 * 删除物料单位
 * @param data
 */
export function delMaterialUnit(data: DelUnit): AxiosPromise<any> {
  return request({
    url: "/stasx/store/materialUnit/delMaterialUnit/v1",
    method: "post",
    data,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
  });
}

/**
 * 新增物料档案
 * @param data
 */
export function addMaterial(data: Material): AxiosPromise<any> {
  return request({
    url: "/stasx/store/material/add/v1",
    method: "post",
    data,
  });
}

/**
 * 修改物料档案
 * @param data
 */
export function updateMaterial(data: Material): AxiosPromise<any> {
  return request({
    url: "/stasx/store/material/update/v1",
    method: "post",
    data,
  });
}

/**
 * 列表物料档案
 * @param data
 */
export function getMaterial(data: MaterialType): AxiosPromise<any> {
  return request({
    url: "/stasx/store/material/list/v1",
    method: "get",
    params: data,
  });
}

/**
 * 物料档案详情
 * @param data
 */
export function getMaterialDetail(data: Detail): AxiosPromise<any> {
  return request({
    url: "/stasx/store/material/detail/v1",
    method: "get",
    params: data,
  });
}

/**
 * 物料档案详情
 * @param data
 */
export function delMaterial(data: Detail): AxiosPromise<any> {
  return request({
    url: "/stasx/store/material/delMaterial/v1",
    method: "post",
    data,
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
  });
}
